package com.rules.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rules.admin.dao.TestLogModelDao;
import com.rules.admin.entity.TestLogModel;
import com.rules.admin.service.TestLogService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("testLogService")
public class TestLogServiceImpl extends ServiceImpl<TestLogModelDao, TestLogModel> implements TestLogService {


   public void delete(String groupId, String artifactId) {
      LambdaQueryWrapper<TestLogModel> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(TestLogModel::getArtifactid,artifactId).eq(TestLogModel::getGroupid,groupId);
      this.baseMapper.delete(queryWrapper);
   }

   public List<TestLogModel> getDeductionNos(Long ruleId, String testId) {
      LambdaQueryWrapper<TestLogModel> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(TestLogModel::getRuleid,ruleId).eq(TestLogModel::getTestid,testId);
      List<TestLogModel> list = this.baseMapper.selectList(queryWrapper);
      return (list.size() > 0 ? list : new ArrayList<TestLogModel>());
   }

   public List<TestLogModel> getByRulePackage(String groupId, String artifactId) {
      LambdaQueryWrapper<TestLogModel> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(TestLogModel::getArtifactid,artifactId).eq(TestLogModel::getGroupid,groupId);
      List<TestLogModel> list = this.baseMapper.selectList(queryWrapper);
      return list;
   }

   public List<TestLogModel> getByTestId(String testId) {
      LambdaQueryWrapper<TestLogModel> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(TestLogModel::getTestid,testId);
      List<TestLogModel> list = this.baseMapper.selectList(queryWrapper);

      return (List)(list.size() > 0 ? list : new ArrayList());
   }
}
